import 'package:flutter/cupertino.dart';
import 'package:get/get_navigation/src/routes/route_middleware.dart';
import 'package:honeypotflutter/net/public_httpInfo.dart';
import 'package:honeypotflutter/public/public_storage.dart';
import 'package:honeypotflutter/publicBussine/bussine_constants.dart';
import 'package:honeypotflutter/publicBussine/loginToken/LoginTokenModel.dart';
import 'package:honeypotflutter/router/bussine_router_url.dart';

class MGLoginMiddleware extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    Map<String, dynamic>? result = HLStorage.getStorage<Map<String, dynamic>>(MGConstants.login_token_info);
    if (result == null) {
      return RouteSettings(name: MGRouterUrl.login);
    }
    LoginTokenModel token = LoginTokenModel.fromJson(result);
    MGHttpInfo.token = token.accessToken ?? "";
    return null;
  }
}
